﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Rbac.Share;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rbac.Server
{
	public class ServerBase
	{
		protected readonly IMapper _mapper;
		protected IHttpContextAccessor _contextAccessor;
		protected int LoginUserId;
		protected ServerBase()
		{
			_mapper=ServiceProviderLocator.Instance.GetService<IMapper>();
			_contextAccessor = ServiceProviderLocator.Instance.GetService<IHttpContextAccessor>();
			//判断一下是否被授权
			if(_contextAccessor.HttpContext!=null)
			{
				if (_contextAccessor.HttpContext.User.Identity.IsAuthenticated)
				{
					LoginUserId = Convert.ToInt32(_contextAccessor.HttpContext.User.Claims.FirstOrDefault(c => c.Type.Equals("UserId")).Value);
				}
			}
			
			
		}

	}
}
